﻿package code.main.view.components {
    import com.yy.base.YYSprite;
    import com.yy.manager.ToolTipManager;
    
    import flash.display.*;

    public class ToolTipBg extends YYSprite {

        private var _triangleSprite:Sprite;
        private var lineColor:uint = 4340766;
        private var lineWidth:uint = 3;
        private var beginColor:uint = 0xFFFFFF;
        private var $ellipse:int = 20;
        private var triangleWidth:int = 14;
        private var triangleHeight:int = 15;
        private var _width:Number = 0;
        private var _height:Number = 0;
        private var _direction:String = "down";

        public function ToolTipBg(){
            this._triangleSprite = new Sprite();
            this._triangleSprite.graphics.beginFill(this.beginColor);
            this._triangleSprite.graphics.lineStyle(this.lineWidth, this.beginColor);
            this._triangleSprite.graphics.moveTo(0, 0);
            this._triangleSprite.graphics.lineTo(this.triangleWidth, 0);
            this._triangleSprite.graphics.lineStyle(this.lineWidth, this.lineColor);
            this._triangleSprite.graphics.lineTo((this.triangleWidth / 2), this.triangleHeight);
            this._triangleSprite.graphics.lineTo(0, 0);
            this._triangleSprite.graphics.endFill();
            addChild(this._triangleSprite);
        }
        public function _draw():void{
            this.graphics.clear();
            this.graphics.lineStyle(this.lineWidth, this.lineColor, 1, true);
            this.graphics.beginFill(this.beginColor);
            this.graphics.drawRoundRect(0, 0, this.width, this.height, this.$ellipse, this.$ellipse);
            this.graphics.endFill();
            this._setPosition();
        }
        private function _setPosition():void{
            switch (this.direction){
                case ToolTipManager.DOWN:
                    this._triangleSprite.rotation = 180;
                    this._triangleSprite.x = (((this.width / 2) - (this.triangleWidth / 2)) + this.triangleWidth);
                    this._triangleSprite.y = 0;
                    break;
                case ToolTipManager.LEFT:
                    this._triangleSprite.rotation = 90;
                    this._triangleSprite.x = 0;
                    this._triangleSprite.y = ((this.height / 2) - (this.triangleWidth / 2));
                    break;
                case ToolTipManager.RIGHT:
                    this._triangleSprite.rotation = 270;
                    this._triangleSprite.x = this.width;
                    this._triangleSprite.y = (((this.height / 2) - (this.triangleWidth / 2)) + this.triangleWidth);
                    break;
                case ToolTipManager.UP:
                    this._triangleSprite.rotation = 0;
                    this._triangleSprite.x = ((this.width / 2) - (this.triangleWidth / 2));
                    this._triangleSprite.y = this.height;
                    break;
            };
        }
        public function get offsetX():Number{
            var _local1:Number = 0;
            switch (this.direction){
                case ToolTipManager.DOWN:
                    _local1 = (this.width / 2);
                    break;
                case ToolTipManager.LEFT:
                    _local1 = -(this.triangleHeight);
                    break;
                case ToolTipManager.RIGHT:
                    _local1 = (this.width + this.triangleHeight);
                    break;
                case ToolTipManager.UP:
                    _local1 = (this.width / 2);
                    break;
            };
            return (_local1);
        }
        public function get offsetY():Number{
            var _local1:Number = 0;
            switch (this.direction){
                case ToolTipManager.DOWN:
                    _local1 = -(this.triangleHeight);
                    break;
                case ToolTipManager.LEFT:
                    _local1 = (this.height / 2);
                    break;
                case ToolTipManager.RIGHT:
                    _local1 = (this.height / 2);
                    break;
                case ToolTipManager.UP:
                    _local1 = (this.height + this.triangleHeight);
                    break;
            };
            return (_local1);
        }
        override public function set width(_arg1:Number):void{
            this._width = _arg1;
            this._draw();
        }
        override public function get width():Number{
            return (this._width);
        }
        override public function set height(_arg1:Number):void{
            this._height = _arg1;
            this._draw();
        }
        override public function get height():Number{
            return (this._height);
        }
        public function get direction():String{
            return (this._direction);
        }
        public function set direction(_arg1:String):void{
            this._direction = _arg1;
            this._setPosition();
        }

    }
}
